from pydantic import BaseModel, Field
import typing as T


class Result(BaseModel):
    code: int = Field(description="返回码")
    msg: T.Optional[str] = Field(None, description="返回信息")
    data: T.Optional[T.Any] = Field(None, description="返回数据")

    @classmethod
    def success(cls, data: T.Any = None):
        return cls(code=1, msg="success", data=data)

    @classmethod
    def error(cls, msg: str = None, data: T.Any = None):
        return cls(code=0, msg=msg, data=data)
